package com.ebupt.migu.music.hangupsms.mapper;

import java.util.List;

import com.ebupt.migu.music.hangupsms.entity.BillInfo;
import com.ebupt.migu.music.hangupsms.entity.IssueInfo;
import com.ebupt.migu.music.hangupsms.entity.UserSendMsgInfo;
import com.ebupt.migu.music.market.entity.MarketSmsStrategy;
import com.ebupt.migu.music.roster.entity.RosterBlackEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

public interface IssueInfoMapper extends BaseMapper<IssueInfo> {
    @Insert(value = "insert into t_migu_hangupmsgsenduser (phonenumber,sendmsgtime,localid,strategy_id) values (#{info.phonenumber},#{info.sendmsgtime},#{info.localid},#{info.strategyId})")
    void save(@Param("info") UserSendMsgInfo info);

    @Select(value = "select phonenumber,sendmsgtime,localid,msgtemplateid from t_migu_hangupmsgsenduser where phonenumber=#{phonenumber} and localid=#{localid}")
    List<UserSendMsgInfo> querySendMsgUserInfo(@Param("phonenumber") String phonenumber, @Param("localid") Integer localId);

    @Select(value = "select * from roster_info where roster_id=#{rosterId}")
    RosterBlackEntity queryRosterBlackEntity(@Param("rosterId") String rosterId);

    @Select(value = "SELECT * FROM market_sms_strategy WHERE execute_status=3 AND target_user='1'\n" +
            "union ALL\n" +
            "SELECT * FROM market_sms_strategy WHERE execute_status=3 AND target_user='2' and user_type=#{billInfo.userType} and FIND_IN_SET(#{billInfo.toneId}, ringtone_id) > 0 and FIND_IN_SET(#{billInfo.callerProvinceId}, call_province) > 0 and #{billInfo.duration} BETWEEN SUBSTRING_INDEX(watch_video_cring_sec, ',', 1) and SUBSTRING_INDEX(watch_video_cring_sec, ',', -1)")
    List<MarketSmsStrategy> queryStrategy(@Param("billInfo") BillInfo billInfo);
}
